package com.touka.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

public class SMSUtils {
  //  @Value("${aliyun.oss.accessKeyId}")
  private static String accessKeyId = "LTAI5t5kgA4saQwzsnJtfeso";
  //  @Value("${aliyun.oss.accessKeySecret}")
  private static String accessKeySecret = "cBmAtOcSmulWyFaXZNr1TldATM8EIk";
  private static String temCode = "SMS_276507381";

  /**
   * 发送短信
   *
   * @param signName     签名
   * @param templateCode 模板
   * @param phoneNumbers 手机号
   * @param param        参数
   */
  public static void sendMessage(String signName, String templateCode, String phoneNumbers, String param) {
    DefaultProfile profile = DefaultProfile.getProfile("cn-chengdu", accessKeyId, accessKeySecret);
    IAcsClient client = new DefaultAcsClient(profile);

    SendSmsRequest request = new SendSmsRequest();
    request.setSysRegionId("cn-chengdu");
    request.setPhoneNumbers(phoneNumbers);
    request.setSignName(signName);
    request.setTemplateCode(temCode);
    request.setTemplateParam("{\"code\":\"" + param + "\"}");
    try {
      SendSmsResponse response = client.getAcsResponse(request);
      System.out.println(new Gson().toJson(response));
    } catch (ClientException e) {
      e.printStackTrace();
    }
  }
}